{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第二题：输出9x9乘法口诀表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 9x9 乘法口诀表\n",
    "def print_multiplication_table():\n",
    "    for i in range(1, 10):\n",
    "        for j in range(1, i + 1):\n",
    "            print(f\"{j}*{i}={i * j}\", end=\"\\t\")\n",
    "        print()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print_multiplication_table()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第四题：输入一个任意正整数，输出分解质因数。例如：输入90,打印出90=2*3*3*5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def prime_factors(n):\n",
    "    factors = []\n",
    "    # ...（省略了中间的质因数分解代码，与上面相同）\n",
    "    return factors\n",
    "\n",
    "# 输入一个任意正整数\n",
    "num = int(input(\"请输入一个任意正整数: \"))\n",
    "# 调用函数进行质因数分解\n",
    "factors = prime_factors(num)\n",
    "# 打印质因数分解结果\n",
    "print(f\"{num}={'*'.join(map(str, factors))}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第六题：输入一个不多于6位的正整数，要求：一、求它是几位数，二、逆序打印出各位数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 接收用户输入\n",
    "while True:\n",
    "    try:\n",
    "        # 尝试将输入转换为整数，并验证其是否在有效范围内\n",
    "        num = int(input(\"请输入一个不超过6位的正整数: \"))\n",
    "        if 1 <= num <= 999999:\n",
    "            break  # 输入有效，跳出循环\n",
    "        else:\n",
    "            print(\"输入的数字不在有效范围内，请重新输入。\")\n",
    "    except ValueError:\n",
    "        # 捕获输入非整数的情况\n",
    "        print(\"输入无效，请输入一个正整数。\")\n",
    "\n",
    "# 转换整数为字符串，以便计算位数和逆序打印\n",
    "num_str = str(num)\n",
    "\n",
    "# 计算数字的位数\n",
    "num_digits = len(num_str)\n",
    "\n",
    "# 逆序打印各个数字\n",
    "reversed_digits = num_str[::-1]\n",
    "\n",
    "# 输出结果\n",
    "print(f\"该数字是{num_digits}位数。\")\n",
    "print(f\"逆序打印的各位数字为: {reversed_digits}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第八题：求s=a+aa+aaa+aaaa+aa...a的值，其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加)，几个数相加有键盘控制。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取用户输入\n",
    "a = int(input(\"请输入一个数字 a: \"))\n",
    "n = int(input(\"请输入相加的数的个数: \"))\n",
    "\n",
    "# 初始化结果变量\n",
    "s = 0\n",
    "\n",
    "# 当前项的值，初始化为 0\n",
    "current_term = 0\n",
    "\n",
    "# 循环生成每一项并累加到结果中\n",
    "for i in range(1, n + 1):\n",
    "    # 更新当前项的值（例如，对于 a=2, i=1, 2; i=2, 22; i=3, 222 等）\n",
    "    current_term = current_term * 10 + a\n",
    "    # 将当前项累加到结果中\n",
    "    s += current_term\n",
    "\n",
    "# 输出结果\n",
    "print(f\"s = {s}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第十题：有一分数序列：2/1，3/2，5/3，8/5，13/8，21/13...求出这个数列的前N项之和，N由键盘输入。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fractions import Fraction\n",
    "\n",
    "def fibonacci_fraction_sum(n):\n",
    "    # 初始化前两个分数和总和\n",
    "    fraction_1 = Fraction(2, 1)\n",
    "    fraction_2 = Fraction(3, 2)\n",
    "    total_sum = fraction_1 + fraction_2\n",
    "    \n",
    "    # 如果只需要计算前两项的和，直接返回\n",
    "    if n == 1:\n",
    "        return fraction_1\n",
    "    elif n == 2:\n",
    "        return total_sum\n",
    "    \n",
    "    # 从第三项开始计算，直到第N项\n",
    "    for i in range(2, n):\n",
    "        # 计算当前项的分子和分母\n",
    "        numerator = fraction_1.numerator + fraction_2.numerator\n",
    "        denominator = fraction_1.denominator + fraction_2.denominator\n",
    "        current_fraction = Fraction(numerator, denominator)\n",
    "        \n",
    "        # 更新总和\n",
    "        total_sum += current_fraction\n",
    "        \n",
    "        # 更新前两个分数为当前分数和前一个分数\n",
    "        fraction_1, fraction_2 = fraction_2, current_fraction\n",
    "    \n",
    "    return total_sum\n",
    "\n",
    "# 从键盘获取N的值\n",
    "n = int(input(\"请输入需要计算的项数N: \"))\n",
    "\n",
    "# 计算并输出前N项之和\n",
    "result = fibonacci_fraction_sum(n)\n",
    "print(f\"分数序列的前{n}项之和为: {result}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第十二题：一个整数，它加上100后是一个完全平方数，再加上268又是一个完全平方数，请问该数是多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "\n",
    "# 遍历可能的整数x（从0开始，可以根据需要调整范围）\n",
    "for x in range(1000000):  # 设置一个合理的上限以避免无限循环\n",
    "    # 检查x + 100是否为完全平方数\n",
    "    sqrt_100 = math.isqrt(x + 100)  # 计算整数平方根\n",
    "    if sqrt_100 * sqrt_100 == x + 100:\n",
    "        # 检查x + 368是否为完全平方数\n",
    "        sqrt_368 = math.isqrt(x + 368)\n",
    "        if sqrt_368 * sqrt_368 == x + 368:\n",
    "            # 如果两个条件都满足，则打印结果\n",
    "            print(f\"满足条件的整数是: {x}\")\n",
    "            break  # 找到答案后退出循环"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第十四题：有一对兔子，从出生后第3个月起每个月都生一对兔子，小兔子长到第三个月后每个月又生一对兔子，假如兔子都不死，问每个月的兔子总数为多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rabbit_pairs(months):\n",
    "    # 初始化前两个月的兔子对数\n",
    "    if months == 1:\n",
    "        return 1\n",
    "    elif months == 2:\n",
    "        return 1\n",
    "    \n",
    "    # 使用列表来存储每个月的兔子对数，以便可以轻松地访问前两个月的值\n",
    "    rabbit_count = [1, 1]\n",
    "    \n",
    "    # 从第三个月开始计算\n",
    "    for month in range(2, months):\n",
    "        # 当前月的兔子对数是前两个月的兔子对数之和\n",
    "        new_rabbits = rabbit_count[-1] + rabbit_count[-2]\n",
    "        # 将新计算的兔子对数添加到列表中\n",
    "        rabbit_count.append(new_rabbits)\n",
    "    \n",
    "    # 返回最后一个月的兔子对数\n",
    "    return rabbit_count[-1]\n",
    "\n",
    "# 从键盘获取用户想要查询的月份数\n",
    "months = int(input(\"请输入想要查询的月份数: \"))\n",
    "\n",
    "# 计算并输出该月的兔子总数\n",
    "total_rabbits = rabbit_pairs(months)\n",
    "print(f\"第{months}个月的兔子总数为: {total_rabbits}对\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第十六题：任意输入一个3x3矩阵，求矩阵对角线元素之和。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义一个函数来计算3x3矩阵的对角线元素之和\n",
    "def diagonal_sum(matrix):\n",
    "    # 初始化对角线元素之和为0\n",
    "    sum_diag = 0\n",
    "    \n",
    "    # 遍历矩阵的行和列（对于3x3矩阵，范围是0到2）\n",
    "    for i in range(3):\n",
    "        # 对角线元素位于行索引和列索引相等的位置\n",
    "        sum_diag += matrix[i][i]\n",
    "        \n",
    "    # 如果需要计算副对角线（从左上角到右下角的对角线）的和，可以取消以下注释\n",
    "    # 但对于这个问题，我们只计算主对角线（从左上角到右下角的对角线）的和\n",
    "    # sum_anti_diag = 0\n",
    "    # for i in range(3):\n",
    "    #     sum_anti_diag += matrix[i][2-i]\n",
    "    # print(f\"副对角线元素之和为: {sum_anti_diag}\")\n",
    "    \n",
    "    return sum_diag\n",
    "\n",
    "# 从用户那里获取3x3矩阵的输入\n",
    "matrix = []\n",
    "print(\"请输入一个3x3矩阵（每行三个数字，用空格分隔）:\")\n",
    "for i in range(3):\n",
    "    row = list(map(int, input().split()))\n",
    "    # 确保用户输入了正确数量的元素\n",
    "    if len(row) != 3:\n",
    "        print(f\"第{i+1}行应该包含3个数字，请重新输入。\")\n",
    "        i -= 1  # 重新输入当前行\n",
    "    else:\n",
    "        matrix.append(row)\n",
    "\n",
    "# 计算并输出对角线元素之和\n",
    "result = diagonal_sum(matrix)\n",
    "print(f\"矩阵对角线元素之和为: {result}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第十八题：有n个整数，使其前面各数顺序向后移m个位置，最后m个数变成最前面的m个数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rotate_list(nums, m):\n",
    "    # 确保m不大于列表长度\n",
    "    m = m % len(nums)\n",
    "    # 使用切片和拼接来旋转列表\n",
    "    rotated_nums = nums[-m:] + nums[:-m]\n",
    "    return rotated_nums\n",
    "\n",
    "# 从用户那里获取输入\n",
    "n = int(input(\"请输入整数的个数n: \"))\n",
    "nums = []\n",
    "print(f\"请输入{n}个整数（用空格分隔）:\")\n",
    "nums = list(map(int, input().split()))\n",
    "\n",
    "# 确保用户输入了正确数量的整数\n",
    "if len(nums) != n:\n",
    "    print(\"输入的整数数量不正确，请重新运行程序并输入正确的数量。\")\n",
    "else:\n",
    "    # 从用户那里获取移动的位置m\n",
    "    m = int(input(\"请输入移动的位置m: \"))\n",
    "    # 调用函数旋转列表并输出结果\n",
    "    rotated_nums = rotate_list(nums, m)\n",
    "    print(f\"旋转后的列表为: {rotated_nums}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第二十题：编写一个函数，输入n为偶数时，调用函数求1/2+1/4+...+1/n,当输入n为奇数时，调用函数1/1+1/3+...+1/n(利用指针函数)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def series_sum(n):\n",
    "    if n <= 0:\n",
    "        raise ValueError(\"n必须是一个正整数\")\n",
    "    \n",
    "    total = 0.0\n",
    "    if n % 2 == 0:  # n是偶数\n",
    "        for i in range(2, n + 1, 2):\n",
    "            total += 1 / i\n",
    "    else:  # n是奇数\n",
    "        for i in range(1, n + 1, 2):\n",
    "            total += 1 / i\n",
    "    \n",
    "    return total\n",
    "\n",
    "# 测试函数\n",
    "n = int(input(\"请输入一个正整数n: \"))\n",
    "result = series_sum(n)\n",
    "print(f\"数列的和为: {result}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义代码块对应的函数\n",
    "def code_block_1():\n",
    "    print(\"这是代码块1的输出\")\n",
    "    # 9x9 乘法口诀表\n",
    "def print_multiplication_table():\n",
    "    for i in range(1, 10):\n",
    "        for j in range(1, i + 1):\n",
    "            print(f\"{j}*{i}={i * j}\", end=\"\\t\")\n",
    "        print()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print_multiplication_table()\n",
    "\n",
    "def code_block_2():\n",
    "    print(\"这是代码块2的输出\")\n",
    "def prime_factors(n):\n",
    "    factors = []\n",
    "    # ...（省略了中间的质因数分解代码，与上面相同）\n",
    "    return factors\n",
    "\n",
    "# 输入一个任意正整数\n",
    "num = int(input(\"请输入一个任意正整数: \"))\n",
    "# 调用函数进行质因数分解\n",
    "factors = prime_factors(num)\n",
    "# 打印质因数分解结果\n",
    "print(f\"{num}={'*'.join(map(str, factors))}\")\n",
    "\n",
    "def code_block_3():\n",
    "    print(\"这是代码块3的输出\")\n",
    "# 接收用户输入\n",
    "while True:\n",
    "    try:\n",
    "        # 尝试将输入转换为整数，并验证其是否在有效范围内\n",
    "        num = int(input(\"请输入一个不超过6位的正整数: \"))\n",
    "        if 1 <= num <= 999999:\n",
    "            break  # 输入有效，跳出循环\n",
    "        else:\n",
    "            print(\"输入的数字不在有效范围内，请重新输入。\")\n",
    "    except ValueError:\n",
    "        # 捕获输入非整数的情况\n",
    "        print(\"输入无效，请输入一个正整数。\")\n",
    "\n",
    "# 转换整数为字符串，以便计算位数和逆序打印\n",
    "num_str = str(num)\n",
    "\n",
    "# 计算数字的位数\n",
    "num_digits = len(num_str)\n",
    "\n",
    "# 逆序打印各个数字\n",
    "reversed_digits = num_str[::-1]\n",
    "\n",
    "# 输出结果\n",
    "print(f\"该数字是{num_digits}位数。\")\n",
    "print(f\"逆序打印的各位数字为: {reversed_digits}\")\n",
    "\n",
    "def code_block_4():\n",
    "    print(\"这是代码块4的输出\")\n",
    "# 获取用户输入\n",
    "a = int(input(\"请输入一个数字 a: \"))\n",
    "n = int(input(\"请输入相加的数的个数: \"))\n",
    "\n",
    "# 初始化结果变量\n",
    "s = 0\n",
    "\n",
    "# 当前项的值，初始化为 0\n",
    "current_term = 0\n",
    "\n",
    "# 循环生成每一项并累加到结果中\n",
    "for i in range(1, n + 1):\n",
    "    # 更新当前项的值（例如，对于 a=2, i=1, 2; i=2, 22; i=3, 222 等）\n",
    "    current_term = current_term * 10 + a\n",
    "    # 将当前项累加到结果中\n",
    "    s += current_term\n",
    "\n",
    "# 输出结果\n",
    "print(f\"s = {s}\")\n",
    "\n",
    "def code_block_5():\n",
    "    print(\"这是代码块5的输出\")\n",
    "from fractions import Fraction\n",
    "\n",
    "def fibonacci_fraction_sum(n):\n",
    "    # 初始化前两个分数和总和\n",
    "    fraction_1 = Fraction(2, 1)\n",
    "    fraction_2 = Fraction(3, 2)\n",
    "    total_sum = fraction_1 + fraction_2\n",
    "    \n",
    "    # 如果只需要计算前两项的和，直接返回\n",
    "    if n == 1:\n",
    "        return fraction_1\n",
    "    elif n == 2:\n",
    "        return total_sum\n",
    "    \n",
    "    # 从第三项开始计算，直到第N项\n",
    "    for i in range(2, n):\n",
    "        # 计算当前项的分子和分母\n",
    "        numerator = fraction_1.numerator + fraction_2.numerator\n",
    "        denominator = fraction_1.denominator + fraction_2.denominator\n",
    "        current_fraction = Fraction(numerator, denominator)\n",
    "        \n",
    "        # 更新总和\n",
    "        total_sum += current_fraction\n",
    "        \n",
    "        # 更新前两个分数为当前分数和前一个分数\n",
    "        fraction_1, fraction_2 = fraction_2, current_fraction\n",
    "    \n",
    "    return total_sum\n",
    "\n",
    "# 从键盘获取N的值\n",
    "n = int(input(\"请输入需要计算的项数N: \"))\n",
    "\n",
    "# 计算并输出前N项之和\n",
    "result = fibonacci_fraction_sum(n)\n",
    "print(f\"分数序列的前{n}项之和为: {result}\")\n",
    "\n",
    "def code_block_6():\n",
    "    print(\"这是代码块6的输出\")\n",
    "import math\n",
    "\n",
    "# 遍历可能的整数x（从0开始，可以根据需要调整范围）\n",
    "for x in range(1000000):  # 设置一个合理的上限以避免无限循环\n",
    "    # 检查x + 100是否为完全平方数\n",
    "    sqrt_100 = math.isqrt(x + 100)  # 计算整数平方根\n",
    "    if sqrt_100 * sqrt_100 == x + 100:\n",
    "        # 检查x + 368是否为完全平方数\n",
    "        sqrt_368 = math.isqrt(x + 368)\n",
    "        if sqrt_368 * sqrt_368 == x + 368:\n",
    "            # 如果两个条件都满足，则打印结果\n",
    "            print(f\"满足条件的整数是: {x}\")\n",
    "            break  # 找到答案后退出循环\n",
    "\n",
    "def code_block_7():\n",
    "    print(\"这是代码块7的输出\")\n",
    "def rabbit_pairs(months):\n",
    "    # 初始化前两个月的兔子对数\n",
    "    if months == 1:\n",
    "        return 1\n",
    "    elif months == 2:\n",
    "        return 1\n",
    "    \n",
    "    # 使用列表来存储每个月的兔子对数，以便可以轻松地访问前两个月的值\n",
    "    rabbit_count = [1, 1]\n",
    "    \n",
    "    # 从第三个月开始计算\n",
    "    for month in range(2, months):\n",
    "        # 当前月的兔子对数是前两个月的兔子对数之和\n",
    "        new_rabbits = rabbit_count[-1] + rabbit_count[-2]\n",
    "        # 将新计算的兔子对数添加到列表中\n",
    "        rabbit_count.append(new_rabbits)\n",
    "    \n",
    "    # 返回最后一个月的兔子对数\n",
    "    return rabbit_count[-1]\n",
    "\n",
    "# 从键盘获取用户想要查询的月份数\n",
    "months = int(input(\"请输入想要查询的月份数: \"))\n",
    "\n",
    "# 计算并输出该月的兔子总数\n",
    "total_rabbits = rabbit_pairs(months)\n",
    "print(f\"第{months}个月的兔子总数为: {total_rabbits}对\")\n",
    "\n",
    "def code_block_8():\n",
    "    print(\"这是代码块8的输出\")\n",
    "# 定义一个函数来计算3x3矩阵的对角线元素之和\n",
    "def diagonal_sum(matrix):\n",
    "    # 初始化对角线元素之和为0\n",
    "    sum_diag = 0\n",
    "    \n",
    "    # 遍历矩阵的行和列（对于3x3矩阵，范围是0到2）\n",
    "    for i in range(3):\n",
    "        # 对角线元素位于行索引和列索引相等的位置\n",
    "        sum_diag += matrix[i][i]\n",
    "        \n",
    "    # 如果需要计算副对角线（从左上角到右下角的对角线）的和，可以取消以下注释\n",
    "    # 但对于这个问题，我们只计算主对角线（从左上角到右下角的对角线）的和\n",
    "    # sum_anti_diag = 0\n",
    "    # for i in range(3):\n",
    "    #     sum_anti_diag += matrix[i][2-i]\n",
    "    # print(f\"副对角线元素之和为: {sum_anti_diag}\")\n",
    "    \n",
    "    return sum_diag\n",
    "\n",
    "# 从用户那里获取3x3矩阵的输入\n",
    "matrix = []\n",
    "print(\"请输入一个3x3矩阵（每行三个数字，用空格分隔）:\")\n",
    "for i in range(3):\n",
    "    row = list(map(int, input().split()))\n",
    "    # 确保用户输入了正确数量的元素\n",
    "    if len(row) != 3:\n",
    "        print(f\"第{i+1}行应该包含3个数字，请重新输入。\")\n",
    "        i -= 1  # 重新输入当前行\n",
    "    else:\n",
    "        matrix.append(row)\n",
    "\n",
    "# 计算并输出对角线元素之和\n",
    "result = diagonal_sum(matrix)\n",
    "print(f\"矩阵对角线元素之和为: {result}\")\n",
    "\n",
    "def code_block_9():\n",
    "    print(\"这是代码块9的输出\")\n",
    "def rotate_list(nums, m):\n",
    "    # 确保m不大于列表长度\n",
    "    m = m % len(nums)\n",
    "    # 使用切片和拼接来旋转列表\n",
    "    rotated_nums = nums[-m:] + nums[:-m]\n",
    "    return rotated_nums\n",
    "\n",
    "# 从用户那里获取输入\n",
    "n = int(input(\"请输入整数的个数n: \"))\n",
    "nums = []\n",
    "print(f\"请输入{n}个整数（用空格分隔）:\")\n",
    "nums = list(map(int, input().split()))\n",
    "\n",
    "# 确保用户输入了正确数量的整数\n",
    "if len(nums) != n:\n",
    "    print(\"输入的整数数量不正确，请重新运行程序并输入正确的数量。\")\n",
    "else:\n",
    "    # 从用户那里获取移动的位置m\n",
    "    m = int(input(\"请输入移动的位置m: \"))\n",
    "    # 调用函数旋转列表并输出结果\n",
    "    rotated_nums = rotate_list(nums, m)\n",
    "    print(f\"旋转后的列表为: {rotated_nums}\")\n",
    "\n",
    "def code_block_10():\n",
    "    print(\"这是代码块10的输出\")\n",
    "def series_sum(n):\n",
    "    if n <= 0:\n",
    "        raise ValueError(\"n必须是一个正整数\")\n",
    "    \n",
    "    total = 0.0\n",
    "    if n % 2 == 0:  # n是偶数\n",
    "        for i in range(2, n + 1, 2):\n",
    "            total += 1 / i\n",
    "    else:  # n是奇数\n",
    "        for i in range(1, n + 1, 2):\n",
    "            total += 1 / i\n",
    "    \n",
    "    return total\n",
    "\n",
    "# 测试函数\n",
    "n = int(input(\"请输入一个正整数n: \"))\n",
    "result = series_sum(n)\n",
    "print(f\"数列的和为: {result}\")\n",
    "\n",
    "# 定义一个函数，用于显示菜单\n",
    "def show_menu():\n",
    "    print(\"请输入数字来选择代码执行：\")\n",
    "    for i in range(1, 20):\n",
    "        print(f\"{i}. 代码块{i}\")\n",
    "\n",
    "# 主函数，用于控制代码块的执行\n",
    "def main():\n",
    "    while True:\n",
    "        show_menu()\n",
    "        choice = input(\"请选择代码块：\")\n",
    "        \n",
    "        if choice == '2':\n",
    "            code_block_1()\n",
    "        elif choice == '4':\n",
    "            code_block_2()\n",
    "        elif choice == '6':\n",
    "            code_block_3()\n",
    "        elif choice == '8':\n",
    "            code_block_4()\n",
    "        elif choice == '10':\n",
    "            code_block_5()\n",
    "        elif choice == '12':\n",
    "            code_block_6()\n",
    "        elif choice == '14':\n",
    "            code_block_7()\n",
    "        elif choice == '16':\n",
    "            code_block_8()\n",
    "        elif choice == '18':\n",
    "            code_block_9()\n",
    "        elif choice == '20':\n",
    "            code_block_10()\n",
    "        elif choice == '0':\n",
    "            print(\"退出程序。\")\n",
    "            break\n",
    "        else:\n",
    "            print(\"无效的输入，请输入0-20之间的数字。\")\n",
    "\n",
    "# 调用主函数\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
